package com.example.fx.fgViewModel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.CategoryEntityResult
import com.example.base.entity.Goods
import com.example.base.entity.GoodsEntityResult
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CateViewModel:BaseViewModel() {
    val cateSuccess = MutableLiveData<CategoryEntityResult>()
    val cateFail = MutableLiveData<String>()
    //请求一二级分类数据
    fun category(){
        viewModelScope.launch {
            try {
                cateSuccess.value = apiService.category()
            }catch (e:Exception){
                cateFail.value = e.message
            }
        }
    }
    //请求三级商品数据
    val threeSuccess = MutableLiveData<GoodsEntityResult>()
    val threeFail = MutableLiveData<String>()
    fun three(cid:Int,page:Int,limit:Int){
        viewModelScope.launch {
            try {
                threeSuccess.value = apiService.three(cid, page, limit)
            }catch (e:Exception){
                threeFail.value = e.message
            }
        }
    }
}